<!--
* description: 值列表查询组件（多选，单选）,支持搜索
* author: liyanm
* createdDate: 2019-07-27
 *   2019-08-05 加入文字溢出效果 liyanm
*  2019-08-09 修改文字溢出效果-封装/校验效果 liyanm
*  2019-10-19 增加sendCode方法 dxuem
-->
<template>
  <section>
    <el-col :span="span">
      <div class="comwidth">
        <lableName
          :validrule="validrule"
          :curLabelName="curLabelName"
          :isShowLabel="isShowLabel"
          :isRequire="isRequire"
        ></lableName>

        <el-select
          :multiple="isMul"
          collapse-tags
          :filterable="filterable"
          v-model="modelCode"
          placeholder="请选择"
          @clear="clearCodeSelect"
          :clearable="clearable"
          @change="sendCode1"
          :disabled="disabled"
          :readonly="readonly"
          size="small"
        >
          <el-option
            v-for="item in optionDatas"
            :key="item[codeField]"
            :label="item[textField]"
            :value="item[codeField]"
          >{{item[textField]}}</el-option>
        </el-select>
        <validateFormate :curLabelName="curLabelName" :validrule="validrule"></validateFormate>
      </div>
    </el-col>
  </section>
</template>
<script>
// import { orgApis } from "@/api/apiList/org";
// import { crmApis } from "@/api/apiList/crm";
import { dropdownMixins } from "@/components/crm/mixins/crmdropdownMix";
// import lableName from "@/components/lableName";
// import validateFormate from "@/components/validateFormate";
export default {
  name: "apiDropList",
  // 组件混入对象：{props[span,isShowLabel,code,isMul,labelName] data[modelCode,optionDatas,listQuery] methods[queryTable,sendCode]}
  mixins: [dropdownMixins],
  components: {
    lableName: () => import("@/components/lableName"), //标题溢出样式组件
    validateFormate: () => import("@/components/validateFormate") //校验提示样式组件
  },
  props: {
    // 值列表类型编码
    lookuptype: { type: Object, default: "_is_null_code_" },
    // 获取组件中的名称，如：textField="carBrandCode"
    codeField: { type: String, default: "lookupValueCode" },
    // 获取组件中的名称，如：textField="carBrandName"
    textField: { type: String, default: "lookupValueName" },
    extralParams: {
      type: Object,
      default: function() {
        return {};
      }
    }
  },
  data() {
    return {
      // API配置对象
      apiConfig: this.lookuptype,
      // 表格中台返回网格的字段
      apiQueryRow: [this.codeField, this.textField],
      // 下拉查询条件
      listQuery: this.getListQuery()
    };
  },
  methods: {
    getListQuery() {
      if (this.extralParams) {
        return Object.assign(this.extralParams);
      } else {
        //  return {isEnable: "1"}
      }
    },
    sendCode1(value) {
      let val = this.modelCode;
      let text = this.codeField;
      this.$emit("changeCode", val, text);
      this.$emit("sendChangeCode", val, text);
      this.$emit("getCode", val, text);
      let that = this;
      let option = that.optionDatas;
      let j = value;
      for (var i = 0; i < option.length; i++) {
        if (option[i][that.codeField] == j) {
          let name = option[i][that.textField];
          this.$emit(
            "changeDropValue",
            j,
            name,
            that.codeField,
            that.textField
          );
        }
      }
      this.sendCode();
    },
    clearCodeSelect() {
      this.sendCode1();
    }
  }
};
</script>
